package leecode;

/**
 * 题目：基于时间戳的键值对简洁写法
 */

import java.util.*;

class TimeMap_ {

    /** Initialize your data structure here. */
    HashMap<String, TreeMap<Integer, String>> map;

    public TimeMap_() {
        map = new HashMap<String, TreeMap<Integer, String>>();
    }

    public void set(String key, String value, int timestamp) {
        map.computeIfAbsent(key, k -> new TreeMap<Integer, String>()).put(timestamp, value);
    }

    public String get(String key, int timestamp) {
        if (!map.containsKey(key)) {
            return "";
        }
        Integer time = map.get(key).floorKey(timestamp);
        if (time == null) {
            return "";
        }
        return map.get(key).get(time);
    }
}